package dictservicelogic

import (
	"context"
	"database/sql"

	"github.com/blog-zero/rpc/model/sysmodel"
	"github.com/blog-zero/rpc/sys/internal/svc"
	"github.com/blog-zero/rpc/sys/sysclient"

	"github.com/zeromicro/go-zero/core/logx"
)

type DictChildenAddLogic struct {
	ctx    context.Context
	svcCtx *svc.ServiceContext
	logx.Logger
}

func NewDictChildenAddLogic(ctx context.Context, svcCtx *svc.ServiceContext) *DictChildenAddLogic {
	return &DictChildenAddLogic{
		ctx:    ctx,
		svcCtx: svcCtx,
		Logger: logx.WithContext(ctx),
	}
}

func (l *DictChildenAddLogic) DictChildenAdd(in *sysclient.DictChildenAddReq) (*sysclient.DictChildenAddResp, error) {
	dictChilden := &sysmodel.SysDictChilden{
		ParentId:    in.ParentId,
		Label:       in.Label,
		Value:       in.Value,
		Description: in.Description,
		Sort:        float64(in.Sort),
		CreateBy:    in.CreateBy,
		Remarks:     sql.NullString{String: in.Remarks, Valid: true},
		Status:      in.Status,
	}
	if _, err := l.svcCtx.DictChildenModel.Insert(l.ctx, dictChilden); err != nil {
		return nil, err
	}

	return &sysclient.DictChildenAddResp{}, nil
}
